<template>
	<view class="goods_list">
		<goodList :goods="ShoppingData" @handleNator="handleNator"></goodList>
	</view>
</template>

<script>
	import goodList from '../../components/goodlist.vue'
	export default {
		data() {
			return {
				ShoppingData:[],
				pageIndex:1
			}
		},
		components:{
			goodList
		},
		methods: {
			async getShoppingData(callbock){
				const res = await this.$request({
					url:"/api/getgoods?pageindex="+this.pageIndex
				})
				this.ShoppingData = [...this.ShoppingData,...res.data.message]
				callbock && callbock()
			},
			handleNator(id){
				uni.navigateTo({
					url:`../goods_detail/goods_detail?id=${id}`
				})
			}
		},
		onLoad() {
			this.getShoppingData()
		},
		// 触底函数
		onReachBottom() {
			if(this.ShoppingData.length < this.pageIndex * 10 ){
				return uni.showToast({
					title:"已经没有更多数据了",
					icon:"none"
				})
			}
			this.pageIndex++;
			this.getShoppingData()
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.ShoppingData = []
			this.pageIndex = 1
			setTimeout(()=>{
				this.getShoppingData(()=>{
					uni.stopPullDownRefresh()
				})
			},1000)
			
		}
	}
</script>

<style lang="less" scoped>
.goods_list{
	background-color: #EEE;
}
</style>
